package com.javalong.affairs.module.schedule.activity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.widget.LinearLayout;

import com.javalong.affairs.R;
import com.javalong.affairs.base.activity.UIHandlerActivity;
import com.javalong.affairs.base.common.ServiceLocator;
import com.javalong.affairs.base.common.UIHandler;
import com.javalong.affairs.base.constant.BundleKey;
import com.javalong.affairs.base.constant.RequestCode;
import com.javalong.affairs.base.fragment.BaseFragment;
import com.javalong.affairs.base.model.Dept;
import com.javalong.affairs.module.recycle.fragment.ScheduleRecycleListFragment;
import com.javalong.affairs.base.ui.TopTitle;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;

@ContentView(R.layout.activity_recycle_schedule)
public class ScheduleRecycleActivity extends UIHandlerActivity {

	@ViewInject(R.id.ui_toptitle)
	private TopTitle topTitle;
	@ViewInject(R.id.ll_root)
	private LinearLayout ll_root;
	private ScheduleRecycleListFragment scheduleRecycleListFragment;
	private BaseFragment currFragment;
	private ArrayList<Map<String, String>> moreList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ViewUtils.inject(this);
		topTitle.setOnLeftDrawableClick(this);
		loadOneFragment();
	}

	// 载入首视图
	private void loadOneFragment() {
		FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
		if (scheduleRecycleListFragment == null) {
			scheduleRecycleListFragment = new ScheduleRecycleListFragment();
		}
		ft.add(R.id.fl_notify, scheduleRecycleListFragment);
		ft.commit();
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == RESULT_OK) {
			switch (requestCode) {
			case RequestCode.DEPTLIST:
				List<Dept> deptList = (List<Dept>) data
						.getSerializableExtra(BundleKey.DEPTLIST);
				Bundle bundle = new Bundle();
				bundle.putSerializable(BundleKey.DEPTLIST,
						(Serializable) deptList);
				UIHandler uiHandler = ServiceLocator.GetInstance().getInstance(
						UIHandler.class);
				uiHandler.postCallback(R.string.event_add_dept, bundle);
				break;
			}
		}
	}
}
